package com.linkhouse.common.domain;


import com.linkhouse.common.em.ResultEnum;

/**
 * ajax返回值
 * */
public class Result<T> {


    private Integer code;
    private String  message;
    private T data;

    //成功
    public static Result ok(){
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getStatus());//自定义返回值码
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }

    //失败
    public static Result error(){
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getStatus());//自定义返回值码
        result.setMessage(ResultEnum.ERROR.getStatusInfo());
        return result;
    }

    //enum
    public static Result response(ResultEnum resultEnum){
        Result result = new Result();
        result.setCode(resultEnum.getStatus());
        result.setMessage(resultEnum.getStatusInfo());
        return result;
    }

    public static Result fallback() {
        Result result = new Result();
        result.setCode(ResultEnum.FEIGN_FALLBACK.getStatus());//自定义返回值码
        result.setMessage(ResultEnum.FEIGN_FALLBACK.getStatusInfo());
        return result;
    }

    //其他
//    public static Result response(Integer code,String message){
//        Result result = new Result();
//        result.setCode(code);
//        result.setMessage(message);
//        return result;
//    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
}
